package com.yonyou.pmclouds.safetyrectification.relationuser.service.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.bp.processor.AuditInfoInsertMultiProcessor;
import com.yonyou.pmclouds.basecom.bp.processor.AuditInfoInsertProcessor;
import com.yonyou.pmclouds.basecom.bp.template.MultiInsertBpTemplate;
import com.yonyou.pmclouds.basecom.bp.template.SingleInsertBpTemplate;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.safetyrectification.relationuser.entity.RelationUserVO;
import com.yonyou.pmclouds.safetyrectification.relationuser.mapper.RelationUserMapper;
import com.yonyou.pmclouds.safetyrectification.relationuser.service.IRelationUserMaintain;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author tanghuan
 * @date 2019/10/26
 */
@Service(interfaceClass = IRelationUserMaintain.class, version = ApplicationConsts.APPLICATION_VERSION)
public class RelationUserMaintainImpl implements IRelationUserMaintain {
    @Autowired
    private RelationUserMapper mapper;

    @Override
    public RelationUserVO add(RelationUserVO vo) throws BusinessException {
        if (vo == null)
            return new RelationUserVO();

        SingleInsertBpTemplate<RelationUserVO> bp = new SingleInsertBpTemplate<>(mapper);
        bp.addBeforeProcessor(new AuditInfoInsertProcessor<RelationUserVO>());

        return bp.insert(vo);
    }

    @Override
    public RelationUserVO[] addVOs(List<RelationUserVO> relationUserVOList) throws BusinessException {
        if (CollectionUtils.isEmpty(relationUserVOList))
            return new RelationUserVO[0];

        MultiInsertBpTemplate<RelationUserVO> bp = new MultiInsertBpTemplate<>(mapper);
        bp.addBeforeProcessor(new AuditInfoInsertMultiProcessor<RelationUserVO>());

        return bp.insert(relationUserVOList.toArray(new RelationUserVO[0]));
    }
}
